package com.tuhu.dsframe.controller;
import com.tuhu.dsframe.entity.Course;
import com.tuhu.dsframe.mapper.CourseMapper;
import com.tuhu.dsframe.service.CourseService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 使用DynamicDataSource框架，通过@DS注解快速切换数据源
 */

@Controller
@RequestMapping("/tuhu")
public class TuhuCourseControllerDS {
    @Resource
    CourseMapper courseMapper;

    @Resource
    CourseService courseService;

    //    localhost:8080/tuhu/queryCourse
    @ResponseBody
    @RequestMapping("/queryCourse")
    public Object queryOrder(){
//        return courseMapper.selectList(null);
        return courseService.selectCourse();
    }

    //    localhost:8080/tuhu/queryCourse1
    @ResponseBody
    @RequestMapping("/queryCourse1")
    public Object queryOrder1(){
//        return courseMapper.selectList(null);
        return courseService.selectCourse1();
    }



//    localhost:8080/tuhu/createCourse
    @ResponseBody
    @RequestMapping("/createCourse")
    public String createCourse(){
//        courseMapper.insert(course);
        Course course = new Course();
        course.setCid(1L);
        course.setCname("aaaaa");
        course.setUserId(1L);
        course.setCstatus("草稿");
        courseService.createCourse(course);
        return "SUCCESS BY DS";
    }
}
